"use strict";
const urlParma = getUrl();
const dialog: any = document.querySelector('#dialog');
const subtype2 = [1, 2, 3, 4, 5, 6, 300, 301, 302];
const subtype3 = [200, 201, 202];
const year = new Date().getFullYear();
$('#year').html(year);
const dialogObj = {
  ok: () => {
    $('#dialog').removeClass('bg-danger text-white').addClass('bg-success text-white').find('a').addClass('text-white');
  },
  no: () => {
    $('#dialog').removeClass('bg-success text-white').addClass('bg-danger text-white').find('a').addClass('text-white');
  },
  open: (t = 5) => {
    $('#dialog').off('animationend').removeClass('animate__fadeOutUp').addClass('animate__fadeInDown');
    dialog.show();
    setTimeout(() => {
      dialogObj.close();
    }, t * 1000);
  },
  close: () => {
    $('#dialog').removeClass('animate__fadeInDown').addClass('animate__fadeOutUp').on('animationend', function () {
      dialog.close();
    });
  }
};
document.querySelector('#closDialog')?.addEventListener('click', (event) => {
  dialogObj.close();
});

function getUrl() {
  const params: any = {};
  const locationUrl = location.search.split('&');
  locationUrl.shift();
  locationUrl.map((item, index) => {
    const arr = item.split('=');
    params[arr[0]] = arr[1];
  });
  return params;
}

function transToTime(time: any) {
  if (time === '0')
    return '00:00';
  let arr1 = time.split('').reverse();
  const start = arr1.length;
  arr1.length = 4;
  arr1.fill('0', start, arr1.length);
  // console.log(JSON.stringify(arr1))
  arr1.splice(2, 0, ':');
  arr1.reverse();
  if (arr1.length !== 5)
    arr1.unshift('0');
  arr1 = arr1.join('');
  return arr1;
}

function GetQueryString(name: any) {
  const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
  const r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
}

function setLan() {
  let lan = GetQueryString('lan') || 'en';
  if (!transLan.hasOwnProperty(lan))
    lan = 'en';
  $('[st]').each((i: any, item: any) => {
    const txt = $(item).attr('st');
    if (txt)
      $(item).html(transLan[lan][txt]);
  });
}
